package com.cy2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class StudentDemo {
    public static void main(String[] args) {
        List<Student> l=new ArrayList<>();
        Student s1=new Student("凌统",25);
        Student s2=new Student("关索",30);
        Student s3 =new Student("留赞",40);
        l.add(s1);
        l.add(s2);
        l.add(s3);
        //迭代器
        ListIterator<Student> lit = l.listIterator();
        while(lit.hasNext()){
            if (lit.next().equals(s1)) {
                lit.add(new Student("chenyong", 24));
            }

        }
        Iterator<Student> it = l.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
           /* l.add(new Student("chenyong",24));
            System.out.println(l);
            System.exit(0);*/
        }
        System.out.println("-----------");
        for (int i = 0; i < l.size(); i++) {
            Student s = l.get(i);
            System.out.println(s);

        }
        System.out.println("------------");
        for (Student s:l){
            System.out.println(s);
        }



    }
}
